<template>
    <div class="history-item">
        <div class="flex justify-between header-info">
            <div class="title" :class="entrust.offset == 'open' ? ' text-green' : 'text-red'">{{
                handleWord(entrust.order_price_type, entrust.offset) }} <span>{{ entrust.name }}</span></div>
            <div class="text" @click.stop="goDetail(entrust.order_no)">
                <span v-if="state == 'submitted'" @click.stop="cancelSingle(entrust.order_no)">{{ $t('撤单') }}</span>
                <span v-if="state == 'created'">{{ $t('已完成') }}</span>
                <span v-if="state == 'canceled'">{{ $t('已撤销') }}</span>
                <van-icon name="arrow" />
            </div>
        </div>
        <div class="flex info">
            <div class="data-item">
                <div class="title">{{ $t('时间') }}</div>
                <div class="text">{{ entrust.create_time ? entrust.create_time.substring(5, entrust.create_time.length) :
                    '--' }}</div>
            </div>
            <div class="data-item right-text">
                <div class="title">{{ $t('委托价') }}（USDT）</div>
                <div class="text">{{ entrust.price }}</div>
            </div>

        </div>
        <div class="flex info">
            <div class="data-item">
                <div class="title">{{ $t('交易额') }}（USDT）</div>
                <div class="text">
                    {{ entrust.offset == 'open' ? entrust.volume : (entrust.volume * entrust.price).toFixed(2) }}
                </div>
            </div>
            <div class="data-item right-text">
                <div class="title">{{ $t('成交总额') }}（USDT）</div>
                <div class="text">
                    {{ entrust.offset == 'open' ? entrust.volume : (entrust.volume * entrust.price).toFixed(2) }}
                </div>
            </div>
        </div>
        <div class="flex info">
            <div class="data-item">
                <div class="title">{{ $t('成交均价') }}（USDT）</div>
                <div class="text">{{ entrust.price }}</div>
            </div>
            <div class="data-item right-text">
                <div class="title">{{ $t('成交量') }}（{{ entrust.symbol }}）</div>
                <div class="text">
                    {{ entrust.offset == 'open' ? (entrust.volume / entrust.price).toFixed(5) : entrust.volume }}
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { Circle } from 'vant'
export default {
    name: 'history-item', // 订单委托项
    components: {
        [Circle.name]: Circle
    },
    props: {
        entrust: {
            type: Object,
            default() {
                return {}
            }
        },
        state: {
            type: String,
            default: ''
        },
        coinPrice: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            text: '0',
            currentRate: 0,
            finishRate: 100,
            finishText: '100%'
        }
    },
    watch: {
    },
    methods: {
        handleWord(type, offset) {
            let str1 = type == 'limit' ? this.$t('限价') : this.$t('市价');
            let str2 = offset == 'open' ? this.$t('买入') : this.$t('卖出');
            return str1 + '/' + str2
        },
        goDetail(order_no) { // 详情
            this.$router.push({ name: 'tradeDetail', query: { order_no } })
        },
        cancelSingle(order_no) { // 撤单
            this.$emit('cancelOrder', order_no)
        }
    }
}
</script>
<style lang="scss"  scoped>
.history-item {
    @include themify() {
        border-bottom: 1px solid themed("line_color");
    }

    padding: 40px 0;

    ::v-deep .van-circle__text {
        @include themify() {
            color: themed("text_color");
        }
    }

    ::v-deep .van-circle__hover {
        @include themify() {
            stroke: themed("color_main");
        }
    }

    .header-info {
        align-items: center;
        padding-bottom: 30px;

        .title {
            font-size: 36px;
            font-weight: 500;
            display: flex;
            align-items: center;

            span {
                color: #fff;
                margin-left: 10px;
            }
        }

        .text {
            font-size: 28px;
            color: #DAD5DC;
        }
    }

    .data-item {
        flex: 1;

        .title {
            color: #868C9A;
            font-size: 24px;
        }

        .text {
            font-size: 28px;

            @include themify() {
                color: themed("text_color");
            }

            margin-top: 10px;
        }
    }

    .right-text {
        text-align: right;
    }

    .center-text {
        text-align: center;
    }

    .info {
        margin-bottom: 40px;
    }
}

.btn-wrap {
    button {
        padding: 0 26px;
        border-radius: 6px;
        font-size: 26px;

    }

    .detailBtn {
        @include themify() {
            border: 1px solid themed("color_main");
        }

        @include themify() {
            color: themed("color_main");
        }

        justify-content: space-between;
    }

}
</style>
